<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Role Class Model</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Role_Class_Model"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Role_Class_Model rootpage-Role_Class_Model skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Role Class Model</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>In computer science, the <b>role class model</b> is a role <a href="Software_analysis_pattern" title="Software analysis pattern">analysis pattern</a><sup id="cite_ref-fowler-role_1-0" class="reference"><a href="#cite_note-fowler-role-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> described (but not invented <sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>) by Francis G. Mossé in his article on Modelling Roles.<sup id="cite_ref-mosse_3-0" class="reference"><a href="#cite_note-mosse-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> The role class pattern provides the ability for a class to play multiple roles and to embed the role characteristic in a dedicated class.
</p><p>In our society, as we built it, roles are everywhere. Anyone trying to work in a team to create something has a role. In <a href="Cinematography" title="Cinematography">cinematography</a>, many different persons take part in the creation of a film: the <a href="Film_director" title="Film director">film director</a>, the <a href="Film_Producer" class="mw-redirect" title="Film Producer">producer</a>, <a href="Actors" class="mw-redirect" title="Actors">actors</a>, <a href="Play_writer" class="mw-redirect" title="Play writer">play writer</a>(s), etc.
Even our State organisations are based on various roles. In a <a href="Republic" title="Republic">Republic</a>, you have a <a href="President_(government_title)" title="President (government title)">President</a>, Ministers, Deputies, etc.
</p><p>Dealing with these situations is one of the problems encountered most during object-oriented analysis. Francis G. Mossé has identified 5 role analysis patterns that can be used to solve most role related problems: Role Inheritance, Association Roles, Role Classes, Generalised Role Classes and Association Class Roles. They all have various degrees of constraints, flexibility or power, which together offer a complete solution to most role-related problems.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Intent">Intent</h2></div>
<p>A model that allows a class to play one or more roles at the same time. A role - as defined by Francis Mossé in Modelling Roles<sup id="cite_ref-mosse_3-1" class="reference"><a href="#cite_note-mosse-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> - is a concept of a purpose that a class could have in a certain context.
</p>
<div class="mw-heading mw-heading2"><h2 id="Context">Context</h2></div>
<p>The following example is given:
</p><p>Many persons work on a film, each of them with a different role. At the difference of other concepts, a person is not restricted to one role. One could be both the <a href="Film_director" title="Film director">director</a> and a character in a film. <a href="Role_play" class="mw-redirect" title="Role play">Modelling</a> roles for such a concept would require that a class could play more than a single role.
</p><p>A solution using <a href="Inheritance" title="Inheritance">inheritance</a> to conceptualise a role - cf. the Inheritance Role Model - is not possible, as this would allow a person to play only a single role. As one can see in Figure 1 below, the inheritance role model says that a character, who is a person, is playing in a film. But there is no way to say that the person playing the character is also the director. Because, the inheritance makes a character a person in general, not a particular person.
</p>
<p></p>
<div class="mw-heading mw-heading2"><h2 id="Problem">Problem</h2></div>
<p>As explained in <a href="#Context">Context</a>, using inheritance to play more than one role cannot be considered, because a class could not play two roles at the same time in such a context (cf. the Inheritance Role Model).
</p><p>The expectation is to have a model where a class could be seen as more than one concept or role, and where attributes specific to one of those concepts can be specified.
</p>
<div class="mw-heading mw-heading2"><h2 id="Solution">Solution</h2></div>
<p>A solution to the previous problem could be to use the Association Role Model, which could create an association between a person and a film. However, specific information on each role could not be stored in such a case. The <i>role class model</i> provides the flexibility of the association with role-specific attributes and even class operations, if needed.
</p>
<p></p>
<p>This meta model - in Figure 2 - shows the role class like an element linking the <i>Client</i> and the <i>BaseClass</i>. For the <i>Client</i> interacting with the <i>Role</i> is like interacting with the <i>Base Class</i> itself, but from the perspective, it is expecting. The advantage having the role as a class is that attributes can be bound to it.
</p><p>Another situation where the Role pattern is interesting is when you've the following situation:
</p>
<p>Then you realise that as a contract holder, the Person has specific attributes. The <i>holder UML role</i> becomes a dedicated class <i>ContractHolder</i> with these specific attributes. Note that in that case that the multiplicity near Person and Contract are always <i>1</i>. It means that you've one <i>ContractHolder</i> object for each association between a Contract and a Person.
</p>
<div class="mw-heading mw-heading3"><h3 id="Real-world_example">Real-world example</h3></div>
<div class="mw-heading mw-heading4"><h4 id="Cinema">Cinema</h4></div>
<p></p>
<p>A simple application of the role class model in a real example is in the 7th art (see <a href="#figure3">Figure 3</a>), the cinematography. This art involves a creation (the Film) and people to create it. Each person has a different role in the film, they could be actors and play characters, they could be director or <a href="Scenarist" class="mw-redirect" title="Scenarist">scenarist</a>, etc. A person is not limited to one role in a film, they can be both actors and directors and even more. For example, the film <a href="Scoop_(2006_film)" title="Scoop (2006 film)">Scoop (2006)</a> has been directed by <a href="Woody_Allen" title="Woody Allen">Woody Allen</a>, he is also the scenarist and he plays the role of Sid Waterman.
</p>
<p></p><p>In <a href="#figure4">Figure 4</a>, one can see in more detail the role that each person can play in a film. From the film, it is possible to ask the list of crews and cast that help elaborated it. Each person has one or more roles (e.g. actor, director, producer, <a href="Cameraman" class="mw-redirect" title="Cameraman">cameraman</a>, etc.) in the film and can participate in more than one film. A person could even be an actor in a film and a producer in another. One advantage of using a role class in the case of the actor role is that the character qualities can be stored within the role. This is true for the actor role, this is also true for other roles, however maybe not all.
</p><p>Only a few of the possible role have been modelled in <a href="#figure4">Figure 4</a>. One remark easily visible is that not all the role needs attributes and using the role class model for all of them is unnecessary (like for the <i>Director</i> role). In addition, there is a lot of redundancy between each role class. Redundancy in <a href="Computer_science" title="Computer science">computer science</a> means more work in maintenance, which is not wished.
</p>
<div class="mw-heading mw-heading2"><h2 id="Strengths_and_weaknesses">Strengths and weaknesses</h2></div>
<p>The employment of this model depends on the <a href="Business_process" title="Business process">business process</a>. The analysis pattern "Role Class Model" offers a possibility to employ a model with linking between a base class and the client. In addition inheritance is not a part of the solution because of the flexibility of zero or multiple roles (role-specific attributes and operations).
Strength implies also its counterpart's weakness. The problem of the role class model is the redundancy, for example the method <i>getName</i> is visible in all of the role classes described in <a href="#figure4">Figure 4</a>. If this is considered inconvenient, the role class generalisation model as defined in Modelling Roles<sup id="cite_ref-mosse_3-2" class="reference"><a href="#cite_note-mosse-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> is a possible way to go.
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<p>Francis G. Mossé<sup id="cite_ref-mosse_3-3" class="reference"><a href="#cite_note-mosse-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> has described other solutions to the role problem.
</p>
<ul><li>Role Inheritance</li>
<li>Association Roles</li>
<li>Generalized Role Classes</li>
<li>Association Class Roles</li>
<li>Association Class Roles with role type, which is a refinement of the previous.</li>
<li>Referential transparency</li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-fowler-role-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-fowler-role_1-0">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFFowler1997" class="citation web cs1"><a href="Martin_Fowler_(software_engineer)" title="Martin Fowler (software engineer)">Fowler, Martin</a> (1997-07-20). <a rel="nofollow" class="external text" href="http://www.martinfowler.com/apsupp/roles.pdf">"Dealing with Roles"</a> <span class="cs1-format">(PDF)</span>. <i>Analysis Pattern</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2007-01-16</span></span>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text">There are a citation about it in the book <i>Business Modeling With UML: Business Patterns at Work by Magnus Penker (Author), <a href="Hans-Erik_Eriksson" title="Hans-Erik Eriksson">Hans-Erik Eriksson</a></i> chapter: <blockquote><p> ...Its origin is unknown, but this pattern has been invoked to model mine-clearance systems used by the United Nations. A description of the concepts underlying this pattern can be found in Murray R. Cantor's book, Object-Oriented Project Management with UML (John Wiley & Sons, Inc., 1998).
</p></blockquote></span>
</li>
<li id="cite_note-mosse-3"><span class="mw-cite-backlink">^ <a href="#cite_ref-mosse_3-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-mosse_3-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-mosse_3-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-mosse_3-3"><sup><i><b>d</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFFrancis_G._Mossé2002" class="citation web cs1">Francis G. Mossé (September 2002). <a rel="nofollow" class="external text" href="http://www.jot.fm/issues/issue_2002_09/column2">"Modeling Roles - A Practical Series of Analysis Patterns"</a>. Journal of Object Technology, vol. 1, no. 4. pp. <span class="nowrap">27–</span>37<span class="reference-accessdate">. Retrieved <span class="nowrap">2006-12-28</span></span>.</cite></span>
</li>
</ol></div>
<div class="mw-heading mw-heading2"><h2 id="Further_reading">Further reading</h2></div>
<ul><li><cite id="CITEREFFowler1996" class="citation book cs1"><a href="Martin_Fowler_(software_engineer)" title="Martin Fowler (software engineer)">Fowler, Martin</a> (1996-11-27). <i>Analysis Patterns: Reusable Object Models</i>. <a href="Addison-Wesley" title="Addison-Wesley">Addison-Wesley</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-201-89542-0</bdi>.</cite> An introduction to object-oriented analysis with conceptual models</li>
<li><cite id="CITEREFRaventós,_Ruth_and_Cabot,_Jordi2006" class="citation journal cs1">Raventós, Ruth and Cabot, Jordi (2006). <a rel="nofollow" class="external text" href="http://www.lsi.upc.edu/~jcabot/papers/JODS05.pdf">"Conceptual Modelling Patterns for Roles"</a> <span class="cs1-format">(PDF)</span>. Journal on Data Semantics V<span class="reference-accessdate">. Retrieved <span class="nowrap">2007-01-16</span></span>.</cite> <span class="cs1-visible-error citation-comment"><code class="cs1-code">{{cite journal}}</code>: </span><span class="cs1-visible-error citation-comment">Cite journal requires <code class="cs1-code">|journal=</code> (help)</span><span class="cs1-maint citation-comment">CS1 maint: multiple names: authors list (link)</span> </li>
<li><cite id="CITEREFDepartment_of_Computer_Science2004" class="citation web cs1">Department of Computer Science (2004). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20070101123419/http://wiki.cs.uiuc.edu/AnalysisPatterns/Asita+%3A+Usage+of+Roles+in+Patterns">"Usage of Roles in Patterns"</a>. <i>Analysis Pattern</i>. University of Illinois at Urbana-Champaign. Archived from <a rel="nofollow" class="external text" href="http://wiki.cs.uiuc.edu/AnalysisPatterns/Asita+%3A+Usage+of+Roles+in+Patterns">the original</a> on 2007-01-01<span class="reference-accessdate">. Retrieved <span class="nowrap">2007-01-16</span></span>.</cite></li>
<li><cite id="CITEREFchromatic2006" class="citation web cs1">chromatic (2006-08-31). <a rel="nofollow" class="external text" href="http://www.oreillynet.com/onlamp/blog/2006/08/roles_composable_units_of_obje.html">"Usage of Roles in Patterns"</a>. <i><a rel="nofollow" class="external text" href="http://www.oreillynet.com/onlamp/blog/technical/">Technical</a></i>. <a href="O'Reilly_Media" title="O'Reilly Media">O'Reilly Media</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2007-01-16</span></span>.</cite> <span class="cs1-visible-error citation-comment"><code class="cs1-code">{{cite web}}</code>: </span><span class="cs1-visible-error citation-comment">External link in <code class="cs1-code"><code class="cs1-code">|work=</code></code> (help)</span></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Related_links">Related links</h2></div>
<ul><li>Actor-Role Pattern, A JPA Implementation <a rel="nofollow" class="external text" href="https://web.archive.org/web/20071105232543/http://www.ibstaff.net/fmartinez/?p=16">https://web.archive.org/web/20071105232543/http://www.ibstaff.net/fmartinez/?p=16</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2023-04-16" href="https://en.wikipedia.org/wiki/?title=Role_Class_Model&oldid=1150210660">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>